package com.achun.getcouponleague.ui.custom;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.achun.getcouponleague.utils.Logutils;

public class LoopViewPager extends ViewPager {
    boolean isLoop = true;

    public LoopViewPager(@NonNull Context context) {
        super(context, null);
    }

    public LoopViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

    }

    public void startLoop() {
        Logutils.e(this.getClass(), "开始滑动--》");
        isLoop = true;
        postDelayed(runnable,4000);
    }

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (isLoop)
                postDelayed(this, 4000);
            int currentItem = getCurrentItem();
            currentItem++;
            setCurrentItem(currentItem);

        }
    };


    public void endLoop() {
        Logutils.e(this.getClass(), "结束滑动--》");
        isLoop = false;
        removeCallbacks(runnable);
    }

}
